"""
    Author: Chris
    Time  : 2019/11/29 20:18
    File  : sms.py
"""
import random
from .settings import *
from utils.logging import logger
from qcloudsms_py import SmsSingleSender
sender = SmsSingleSender(APP_ID, APP_KEY)

def send_sms(mobile, code, exc):
    try:
        resposes = sender.send_with_param(86, mobile,TEMPLATE_ID, (code,exc), sign=SMS_SING)
        msg = resposes.get('result')
        if resposes and msg == 0:
            return True
    except Exception as msg:
        pass
    logger.error(f'短信发送失败{msg}')
    return False





def get_code():
    code = ''
    for i in range(4):
        code += str(random.randint(0, 9))

    return code
